package com.diaohw.module.metadata.controller.dictionary;

import com.diaohw.module.metadata.obj.dto.DictionaryItemDTO;
import com.diaohw.module.metadata.obj.entity.DictionaryItemDO;
import com.diaohw.module.metadata.obj.query.DictionaryItemQuery;
import com.diaohw.module.metadata.obj.vo.DictionaryItemVO;
import com.diaohw.module.metadata.service.DictionaryItemService;
import com.diaohw.platform.common.obj.page.PageResultVo;
import com.diaohw.platform.common.validator.InsertGroup;
import com.diaohw.platform.common.validator.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 数据字典项信息表 前端控制器
 * </p>
 *
 * @author D-Hw
 * @since 2024-09-18
 */
@Tag(name = "数据字典项信息表")
@RestController
@RequestMapping("/dictionary-item")
public class DictionaryItemController {

    @Resource
    private DictionaryItemService service;

    @PostMapping
    @Operation(summary = "新增")
    public DictionaryItemVO create(@RequestBody @Validated(InsertGroup.class) DictionaryItemDTO data) {
        return service.create(data);
    }

    @PutMapping("/{id}")
    @Operation(summary = "更新")
    public DictionaryItemVO update(@PathVariable("id") String id, @RequestBody @Validated(UpdateGroup.class) DictionaryItemDTO data) {
        return service.update(id, data);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除")
    public Boolean delete(@PathVariable("id") String id) {
        return service.delete(id);
    }

    @GetMapping("/{id}")
    @Operation(summary = "依据ID查看信息")
    public DictionaryItemVO detail(@PathVariable("id") String id) {
        return service.detail(id);
    }

    @Operation(summary = "依据ID集合查询")
    @GetMapping("/batch")
    public List<DictionaryItemVO> findById(List<String> ids) {
        List<DictionaryItemDO> list = service.listByIds(ids);
        return DictionaryItemService.INSTANCE.entityToVo(list);
    }

    @GetMapping
    @Operation(summary = "查询列表")
    public List<DictionaryItemVO> all(DictionaryItemQuery query) {
        return service.findByList(query);
    }

    @GetMapping("/page")
    @Operation(summary = "分页查看")
    public PageResultVo<DictionaryItemVO> page(DictionaryItemQuery query) {
        return service.findByPage(query);
    }

}
